package com.twu.biblioteca;


import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.io.BufferedReader;

public class InputOutput
{
    public void welcomeMessage()
    {
        System.out.println("Welcome to Biblioteca");
    }

    public void listBooks(LinkedList<Book> books)
    {
        System.out.println("Available Books:");
        for (Book book: books)
        {
            if (!book.getCheckedOut())
                System.out.println(book.getName());
        }
        System.out.println("Unavailable Books:");
        for (Book book: books)
        {
            if (book.getCheckedOut())
                System.out.println(book.getName());
        }
    }

    public void displayMenu(boolean loggedIn)
    {
        if (loggedIn)
        {
            System.out.println("Menu:");
            System.out.println("A:List Books");
            System.out.println("B:Checkout a Book");
            System.out.println("C:Return a Book");
            System.out.println("D:List Movies");
            System.out.println("E:Checkout a Movie");
            System.out.println("F:Return a Movie");
            System.out.println("H:Show account information");
            System.out.println("X:Exit");
            System.out.println("To use the menu, type the letter in front of the command:");
        }
        else
        {
            System.out.println("Menu:");
            System.out.println("A:List Books");
            System.out.println("D:List Movies");
            System.out.println("G:Login");
            System.out.println("X:Exit");
            System.out.println("To use the menu, type the letter in front of the command:");
        }
    }

    public String getUserInput()
    {
        try
        {
            BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
            return bufferRead.readLine();
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
        return "";
    }

    public void selectValidInput()
    {
        System.out.println("Select a valid option!");
    }

    public void checkOutBookHeading()
    {
        System.out.println("Select a book to checkout by typing the book's name.");
    }

    public void bookCheckedOut()
    {
        System.out.println("Thank you! Enjoy the book");
    }

    public void bookUnavailable()
    {
        System.out.println("That book is not available.");
    }

    public void returnBookHeading()
    {
        System.out.println("Select a book to return by typing the book's name.");
    }

    public void listCheckedOutBooks(LinkedList<Book> books)
    {
        System.out.println("Books to be returned:");
        for (Book book: books)
            if (book.getCheckedOut())
                System.out.println(book.getName());
    }

    public void bookReturned()
    {
        System.out.println("Thank you for returning the book.");
    }

    public void bookNotAbleToBeReturned()
    {
        System.out.println("That is not a valid book to return.");
    }

    public void listMovies(LinkedList<Movie> movies)
    {
        System.out.println("Available Movies");
        for (Movie movie: movies)
            if (!movie.getCheckedOut())
                System.out.println(movie.getName());
        System.out.println("Unavailable Movies");
        for (Movie movie: movies)
            if (movie.getCheckedOut())
                System.out.println(movie.getName());
    }

    public void checkOutMovieHeading()
    {
        System.out.println("Select a book to checkout by typing the movie's name.");
    }

    public void movieCheckedOut()
    {
        System.out.println("Thank you! Enjoy the movie");
    }

    public void movieReturned()
    {
        System.out.println("Thank you for returning the movie.");
    }

    public void movieUnavailable()
    {
        System.out.println("That movie is not available.");
    }

    public void returnMovieHeading()
    {
        System.out.println("Select a movie to return by typing the movie's name.");
    }

    public void listCheckedOutMovies(LinkedList<Movie> movies)
    {
        System.out.println("Movies to be returned:");
        for (Movie movie: movies)
            if (movie.getCheckedOut())
                System.out.println(movie.getName());
    }

    public void movieNotAbleToBeReturned()
    {
        System.out.println("That is not a valid movie to return.");
    }

    public void youMustBeLoggedIn()
    {
        System.out.println("You must be logged in to do that.");
    }

    public void loginUseLibraryNumber()
    {
        System.out.println("Please enter your library number:");
    }

    public void loginUsePassword()
    {
        System.out.println("Please enter your library password:");
    }

    public void successfulLogin(String userName)
    {
        System.out.println("Welcome " + userName + ". You are successfully logged in.");
    }

    public void unsuccessfulLogin()
    {
        System.out.println("Incorrect details. You are not logged in.");
    }

    public void displayUserInfo(String[] loggedInUserInfo)
    {
        System.out.println("Name: " + loggedInUserInfo[0] + " Library number: " + loggedInUserInfo[1] + " Email address: " + loggedInUserInfo[2] + " Phone number: " + loggedInUserInfo[3]);
    }
}
